package cn.jingyuan.swan.system.domain.gateway.dao.mysql;

import cn.jingyuan.swan.cloud.dao.DaoException;
import cn.jingyuan.swan.cloud.dao.mybatisplus.AbstractMyBatisPlusCrudDao;
import cn.jingyuan.swan.system.domain.gateway.dao.GatewayRouteDao;
import cn.jingyuan.swan.system.domain.gateway.entity.GatewayRoute;
import cn.jingyuan.swan.system.domain.gateway.mapper.GatewayRouteMapper;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.springframework.stereotype.Repository;

import javax.annotation.Resource;
import java.util.List;

@Repository
public class GatewayRouteDaoMySql extends AbstractMyBatisPlusCrudDao<GatewayRoute, Long> implements GatewayRouteDao {

    @Resource
    GatewayRouteMapper mapper;

    @Override
    public GatewayRoute getByRouteName(String routeName) {
        LambdaQueryWrapper<GatewayRoute> wrapper = this.queryWrapper()
            .eq(GatewayRoute::getRouteName, routeName);

        try {
            return mapper.selectOne(wrapper);
        } catch (Exception e) {
            throw new DaoException(e);
        }
    }

    @Override
    public List<GatewayRoute> listByQueryWrapper(LambdaQueryWrapper<GatewayRoute> wrapper) {
        try {
            return mapper.selectList(wrapper);
        } catch (Exception e) {
            throw new DaoException(e);
        }
    }

    @Override
    public int countByQueryWrapper(LambdaQueryWrapper<GatewayRoute> wrapper) {
        try {
            return mapper.selectCount(wrapper);
        } catch (Exception e) {
            throw new DaoException(e);
        }
    }

    @Override
    public BaseMapper<GatewayRoute> getMapper() {
        return this.mapper;
    }

}
